<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="shortcut icon" href="${ctx}/favicon.ico"> <link href="${ctx}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx}/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
       <div class="table-responsive" style="margin:2%;">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>商品编号</th>
                        <th>商品名称</th>
                        <th>商品分类</th>
                        <th>单价</th>
                        <th>规格</th>
                        <th>产地</th>
                        <th>介绍</th>
                        <th>备注</th>
                        <th>数据恢复</th>
                        <th>彻底清除</th>                        
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="goods" items="${goodslist}">
                    	<tr id="${goods.goods_id}">
                    		<td >${goods.goods_id}</td>
                            <td>${goods.goods_name}</td>
                            <td>${goods.goods_classification}</td>
                            <td>${goods.price}</td>
                            <td>${goods.unit}</td>
                            <td>${goods.origin}</td>
                            <td>${goods.introduce}</td>
                            <td>${goods.remark}</td>
                            <td>
                            <a class="btn btn-primary btn-rounded" onclick="makeRegain(${goods.goods_id})">恢复</a>
                        	</td>
                        	<td>
                            	<a class="btn btn-primary btn-rounded" onclick="makeDelete(${goods.goods_id})">清除</a>
                        	</td>
                    	</tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
            <div>
                    <!-- <span style="float:left;">共25条数据5页</span> -->
                    <div id="page" style="text-align:right;"></div>
            </div>
</body>
<script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctx}/dist\layer-v3.1.1\layer\layer.js"></script>
<script src="${ctx}/dist/jquery-bootstrap-pagination/jquery-bootstrap-pagination.js"></script>
<script>
	//分页
    $("#page").pagination({
		  total_pages:${pageCount},
		  current_page:${pageNum},
		  prev: "上一页",
		  next: "下一页",
		  display_max:4,
		  callback: function(event, page) {
		      //return alert("Page " + page + " was clicked!");
		      location="${ctx}/RegainServlet/getGoodsList?pageNum="+page;
		}
		}); 
	//恢复
	function makeRegain(goods_id){
		$.get('${ctx}/RegainServlet/regainGoods',{'goods_id':goods_id},function(data){
    		if(data){
				layer.msg('恢复成功');
				//在页面表中删除数据
				document.getElementById(goods_id).parentNode.removeChild(document.getElementById(goods_id));
			}else{
				layer.msg('恢复失败');
			}
    	});    
	}
	//清除
	function makeDelete(goods_id){
		if(confirm('确定删除所选吗？')){
			$.get('${ctx}/RegainServlet/deleteGoods',{'goods_id':goods_id},function(data){
	    		if(data){
					layer.msg('清除成功');
					//在页面表中删除数据
					document.getElementById(goods_id).parentNode.removeChild(document.getElementById(goods_id));
				}else{
					layer.msg('清除失败');
				}
	    	});   
		}
	}
</script>
</html>